<template>
	<view>
		<view class="search-box">
			<my-search @searchclick="gotoSearch"></my-search>
		</view>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item , index) in swiperList" :key="index">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.id">
					<image :src="item.url"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<view class="nav-list">
			<view class="nav-item" v-for="(item,index) in navList" :key="index" @click="navClickHander(item)">
				<image :src="item.url" class="nav-img"></image>
				<view>{{item.name}}</view>
			</view>
		</view>
		<view class="floor-list">
			<view class="floor-item" v-for="(item,index) in floorList" :key="index">
				<image :src="item.cates.imgUrl" class="floor-title"></image>
				<view class="floor-img-box">
					<navigator class="left-img-box" :url="item.cateStores[0].navUrl">
						<image :src="item.cateStores[0].imgurl" class="img-css"></image>
					</navigator>
					<view class="right-img-box">
						<navigator class="right-img-item" v-for="(item2,index2) in item.cateStores" :key="index2" :url="item2.navUrl">
							<image v-if="index2 !== 0" :src="item2.imgurl" class="img-css2"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tabbarBadge from "@/mixins/tabbar-badge.js";
	export default {
		mixins:[tabbarBadge],
		data() {
			return {
				swiperList: [],
				navList: [],
				floorList: []
			};
		},
		onLoad() {
			this.getSwiperList();
			this.getNavList();
			this.getFloorList()
		},
		methods: {
			async getSwiperList() {
				const {
					data: res
				} = await uni.$http2.get('/user/swiperImgList')
				if (res.code !== 200) {
					// return uni.showToast({
					// 	title: '数据请求失败！',
					// 	duration: 1500,
					// 	icon: 'none'
					// })
					return uni.$showMsg()
				}
				this.swiperList = res.data
			},
			async getNavList() {
				const {
					data: res
				} = await uni.$http2.get('/user/uniappimg1');
				if (res.code !== 200) {
					return uni.$showMsg()
				}
				this.navList = res.data

			},
			navClickHander(item) {
				if (item.name === '分类') {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			async getFloorList() {
				const {
					data: res
				} = await uni.$http2.get("/user/floorlist")
				if (res.code !== 200) {
					return uni.$showMsg()
				}
				this.floorList = res.data
			},
			gotoSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
	swiper {
		height: 330rpx;

		.swiper-item,
		image {
			width: 100%;
			height: 100%;
		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 15px 0;
	}

	.nav-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.nav-img {
		width: 128rpx;
		height: 140rpx;
	}

	.floor-title {
		height: 60rpx;
		width: 200rpx;
	}
	.img-css{
		height: 500rpx;
		width: 300rpx;
	}
	.img-css2{
		height: 220rpx;
		width: 220rpx;
	}
	.right-img-box{
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}
	.floor-img-box{
		display: flex;
		padding-left: 10rpx;
	}
	.search-box{
		position: sticky;
		top: 0;
		z-index: 999;
	}
</style>